/**   
 * @Title: ApplicationController.java 
 * @Package org.playgod1984.du.base 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author playgod playgod1984@163.com  
 * @date 2014年10月15日 上午11:23:34 
 * @version V1.0   
 */
package org.playgod1984.du.base;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import org.playgod1984.du.auth.model.User;
import org.playgod1984.du.base.util.DuDesignUtil;

import com.jfinal.core.Controller;

/** 
 * @ClassName: ApplicationController 
 * @Description: TODO(这里用一句话描述这个类的作用) 
 * @author playgod playgod1984@163.com 
 * @date 2014年10月15日 上午11:23:34 
 *  
 */
@SuppressWarnings("all")
public class ApplicationController extends Controller {
	private static final String LIGER_WHERE="where";
	public static final String RES_SUCCESS="1";
	public static final String RES_FAILED="0";
	/**
	 * 传入参数名
	 * @param paramNames
	 * @return
	 */
	public Map<String,String> getParamsMap(){
		Map params = new HashMap();
		Enumeration<String> paramNames = getParaNames();
		// traverse(遍历) paramNames
		while(paramNames.hasMoreElements()){
           String name=(String)paramNames.nextElement();
           params.put(name, getPara(name));
        }
		params.put("currentUser", getCurrentUser().getStr("loginaccount"));
		return params;
	}
	
	/**
	 * @Title: getDataGridFilter
	 * @author:playgod playgod1984@163.com 
	 * @Description: liger ui filter conditions 
	 * @param @return    设定文件 
	 * @return Map    返回类型 
	 * @throws
	 */
	public Map getDataGridFilter(){
		String where = getPara(LIGER_WHERE);
//		{"rules":[{"field":"loginaccount","op":"equal","value":"sxm","type":"string"}],"op":"and"}
		if(where != null && where.length()>1){
			return DuDesignUtil.parseJSON2Map(where);
		}else{
			return new HashMap();
		}
	}
	/**
	 * @Title: getCurrentUser
	 * @author:playgod playgod1984@163.com 
	 * @Description: Get currentUser who is logining
	 * @param @return    设定文件 
	 * @return User    返回类型 
	 * @throws
	 */
	public User getCurrentUser(){
		User user = (User)this.getSession().getAttribute("currentUser");
		return user;
	}
}
